package com.icinfo.cloud.provider.punish.common.log.service.impl;

import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.punish.common.log.dto.SysLogQueryDto;
import com.icinfo.cloud.provider.punish.common.log.mapper.SysLogMapper;
import com.icinfo.cloud.provider.punish.common.log.model.SysLog;
import com.icinfo.cloud.provider.punish.common.log.service.ISysLogService;
import com.icinfo.cloud.provider.punish.common.log.vo.SysLogQueryVO;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import com.icinfo.framework.tools.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述: 系统日志表 sys_log 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2023年05月09日
 */
@Service
@Slf4j
public class SysLogServiceImpl extends MyBatisServiceSupport implements ISysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public void save(SysLog sysLog) {
        UserDTO user = UserUtil.getUserInfo();
        sysLog.setId(StringUtils.uuid());
        sysLog.setOperatorName(user.getRealName());
        sysLog.setOperatorOrgCode(user.getOrgCode());
        sysLog.setOperatorOrgName(user.getOrgName());
        sysLog.setOperateTime(DateUtil.getCurrLocalDateTime());
        sysLogMapper.insertSelective(sysLog);
    }

    @Override
    public List<SysLogQueryVO> query(SysLogQueryDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getLength());
        return sysLogMapper.query(dto);
    }
}